package cn.it.shop.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import cn.it.shop.model.Category;
import cn.it.shop.service.CategoryService;

@Service("categoryService")
@SuppressWarnings("unchecked")
public class CategoryServiveImpl extends BaseServiveImpl<Category> implements
		CategoryService {
	public static void main(String[] args) {
		new CategoryServiveImpl();
	}

	public List<Category> queryJoinAccount(String type, int page, int size) {
		String hql = "FROM Category c LEFT JOIN FETCH c.account WHERE c.type LIKE :type";
		return getSession().createQuery(hql).setFirstResult((page - 1) * size)
				.setMaxResults(size).setString("type", "%" + type + "%").list();
	}

	public long getCount(String type) {
		String hql = "SELECT count(c) FROM Category c WHERE c.type LIKE :type";
		return (Long) getSession().createQuery(hql)
				.setString("type", "%" + type + "%").uniqueResult();

	}

	@Override
	public void deleteByIds(String ids) {
		String hql = "DELETE Category c WHERE c.id in (" + ids + ")";
		getSession().createQuery(hql).executeUpdate();

	}

	@Override
	public List<Category> queryByHot(boolean hot) {
		String hql = "FROM Category c WHERE c.hot=:hot";
		return getSession().createQuery(hql)//
				.setBoolean("hot", hot)//
				.list();//
	}
}
